package org.forum.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.struts2.json.annotations.JSON;

@Entity
@Table(name="main_topic")
public class MainTopic implements Serializable{
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(nullable=false, unique=true)
	private Integer mainTopicId;
	
	@Column(nullable=false)
	private Integer publisherId;
	
	private String title;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable=false)
	private Date addTime;
	
	//mark whether it is a announcement
	@Column(nullable=false)
	private Boolean isAnnouncement;
	
	private String essay;
	
	//周访问量
	private Long weekview;
	//
	private String classification;
	
	@ManyToOne(targetEntity=User.class)
	@JoinColumn(name="userId",referencedColumnName="userId", nullable=false)
	private User user;
	
	@ManyToOne(targetEntity=Forum.class)
	@JoinColumn(name="forumId", referencedColumnName="forumId", nullable=false)
	private Forum forum;
	
	@OneToMany(targetEntity=ViceTopic.class,mappedBy="mainTopic")
	private Set<ViceTopic> viceTopics = new HashSet<>();
	
	@OneToMany(targetEntity=Picture.class)
	@JoinColumn(name="mainTopicId", referencedColumnName="mainTopicId")
	private Set<Picture> pictures= new HashSet<>();

	public Integer getMainTopicId() {
		return mainTopicId;
	}

	public void setMainTopicId(Integer mainTopicId) {
		this.mainTopicId = mainTopicId;
	}

	public Integer getPublisherId() {
		return publisherId;
	}

	public void setPublisherId(Integer publisherId) {
		this.publisherId = publisherId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Date getAddTime() {
		return addTime;
	}

	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	
	public Boolean getIsAnnouncement() {
		return isAnnouncement;
	}

	public void setIsAnnouncement(Boolean isAnnouncement) {
		this.isAnnouncement = isAnnouncement;
	}

	public String getEssay() {
		return essay;
	}

	public void setEssay(String essay) {
		this.essay = essay;
	}

	public Long getWeekview() {
		return weekview;
	}

	public void setWeekview(Long weekview) {
		this.weekview = weekview;
	}

	public String getClassification() {
		return classification;
	}

	public void setClassification(String classification) {
		this.classification = classification;
	}
	
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	@JSON(serialize=false)
	public Forum getForum() {
		return forum;
	}

	public void setForum(Forum forum) {
		this.forum = forum;
	}
	@JSON(serialize=false)
	public Set<ViceTopic> getViceTopics() {
		return viceTopics;
	}

	public void setViceTopics(Set<ViceTopic> viceTopics) {
		this.viceTopics = viceTopics;
	}
	@JSON(serialize=false)
	public Set<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(Set<Picture> pictures) {
		this.pictures = pictures;
	}
}
